﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
public partial class Manage_Emp1_ClassCurLearn : AdminPageBase
{
    int id;
    int classtypeid = 0;
    protected int FinishClass = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckAdmin();
        GetUserPermisions();
        GetEmpId();
        if (!IsPostBack)
        {
            // 正确的属性设置方法
            this.GridView1.Attributes.Add("SortExpression", "StudyId");
            this.GridView1.Attributes.Add("SortDirection", "ASC");
            this.GridView2.Attributes.Add("SortExpression", "ClassId");
            this.GridView2.Attributes.Add("SortDirection", "ASC");
            DataTable dt = new DataTable();
            dt.Columns.Add("ClassId");
            dt.Columns.Add("ClassTypeId");
            dt.Columns.Add("Code");
            dt.Columns.Add("ClassTypeName");
            dt.Columns.Add("Name");
            dt.Columns.Add("Time");

            dt.Columns.Add("IsValidDesc");
            dt.Columns.Add("");
            GridviewControl.GridViewDataBind(this.GridView2, dt);
            GridviewControl.ResetGridView(this.GridView2);
            BindClass();
            BindClassType();
            BindSelectClass();
        }
    }
    protected void GetEmpId()
    {
        if (Request.QueryString["id"] == null)
        {
            id = 0;

        }
        else
        {
            id = Convert.ToInt32(Request.QueryString["id"]);

        }
    }
    protected void CheckAdmin()
    {
        if (AdminSessionHelper.UserDetails == null)
        {
            JsHelper.TopAlertRedirect("请先登录", "../login.aspx", this.Page);
        }
    }
    protected void BindClassType()
    {
        DataSet ds = jtDataAccess.SearchClassType("",10,0,"Name","ASC");
        if (CoreTools.CheckDataSet(ds))
        {
            ddlctype.DataSource = ds;
            ddlctype.DataTextField = "Name";
            ddlctype.DataValueField = "ClassTypeId";
            ddlctype.DataBind();
        }
        ListItem item = new ListItem("选择课程类型","0");
        ddlctype.Items.Insert(0,item);

    }
    protected void BindClass()
    {
        if (id != 0)
        {
            // 获取GridView排序数据列及排序方向
            string sortExpression = this.GridView1.Attributes["SortExpression"];
            string sortDirection = this.GridView1.Attributes["SortDirection"];

            DataSet ds = jtDataAccess.GetEmpInfo(id);
            if (CoreTools.CheckDataSet(ds))
            {
                FinishClass = Convert.ToInt32(ds.Tables[0].Rows[0]["FinishClass"].ToString());
                hdfFinishClass.Value = FinishClass.ToString();

            }
            if (ds != null&&ds.Tables.Count >2&&ds.Tables[2].Rows.Count > 0)
            {
                // 根据GridView排序数据列及排序方向设置显示的默认数据视图
                if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
                {
                    ds.Tables[2].DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
                }

                // GridView绑定并显示数据
               // this.GridView1.DataSource = ds.Tables[2];
                //this.GridView1.DataBind();
                GridviewControl.GridViewDataBind(this.GridView1, ds.Tables[2]);
                if (FinishClass == 1)
                {
                    btnexport.Visible = true;
                    Button1.Enabled = true;
                    selectAll1.Enabled = true;
                    ibtnsearch.Enabled = true;
                }
                else
                {
                    btnexport.Visible = false;
                    Button1.Enabled = false;
                    selectAll1.Enabled = false;
                    ibtnsearch.Enabled = false;
                }
            }
            else
            {
              // this.GridView1.DataSource = null;
                //this.GridView1.DataBind();
                DataTable dt = new DataTable();
                dt.Columns.Add("StudyId");
                dt.Columns.Add("ClassId");
                dt.Columns.Add("Code");
                dt.Columns.Add("ClassTypeName");
                dt.Columns.Add("Name");
                dt.Columns.Add("Time");
                dt.Columns.Add("IsValidDesc");
                dt.Columns.Add("StartDate", typeof(DateTime));
                dt.Columns.Add("EndDate", typeof(DateTime));
                dt.Columns.Add("");
                GridviewControl.GridViewDataBind(this.GridView1, dt);
                GridviewControl.ResetGridView(this.GridView1);
                btnexport.Visible = false;
                Button1.Enabled = false;
                selectAll1.Enabled = false;
            }
        }
        else
        {
            // this.GridView1.DataSource = null;
            //this.GridView1.DataBind();
            DataTable dt = new DataTable();
            dt.Columns.Add("StudyId");
            dt.Columns.Add("ClassId");
            dt.Columns.Add("Code");
            dt.Columns.Add("ClassTypeName");
            dt.Columns.Add("Name");
            dt.Columns.Add("Time");
            dt.Columns.Add("IsValidDesc");
            dt.Columns.Add("StartDate", typeof(DateTime));
            dt.Columns.Add("EndDate", typeof(DateTime));
            dt.Columns.Add("");
            GridviewControl.GridViewDataBind(this.GridView1, dt);
            GridviewControl.ResetGridView(this.GridView1);
            btnexport.Visible = false;
            Button1.Enabled = false;
            selectAll1.Enabled = false;
        }
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindClass();
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindClass();
        GridviewControl.ResetGridView(this.GridView2);
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        int flag = 0;
        int studyid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
        int classid=Convert.ToInt32(((HiddenField)GridView1.Rows[e.RowIndex].FindControl("hdfclassId")).Value);
        DateTime? sdate =null;
        DateTime? edate = null;
 
        TextBox sdatec=(TextBox)GridView1.Rows[e.RowIndex].FindControl("txtStartDate");
        TextBox edatec=(TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEndDate");
        if (sdatec.Text.Trim() == "")
            sdate = null;
        else
            sdate = DateTime.Parse(sdatec.Text.Trim());
        if (edatec.Text.Trim()== "")
            edate = null;
        else
            edate = DateTime.Parse(edatec.Text.Trim());
        UserType ut = new UserType();//用户自定义类型
        DataTable StudyTable = ut.GetStudyTableType();
        DataRow StudyTableRow;
        StudyTableRow = StudyTable.NewRow();
        StudyTableRow["StudyId"] = studyid;
        StudyTableRow["EmpId"] = id;
        StudyTableRow["ClassId"] = classid;
        if (sdate == null)
            StudyTableRow["StartDate"] = DBNull.Value;
        else
            StudyTableRow["StartDate"] = sdate;
        if (edate == null)
            StudyTableRow["EndDate"] = DBNull.Value;
        else
            StudyTableRow["EndDate"] = edate;
        StudyTable.Rows.Add(StudyTableRow);
        flag = jtDataAccess.OpStudy(JTDataAccess.OpType.Update, StudyTable);
        switch (flag)
        {
            case 1:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作成功！"), false);
                break;
            case 0:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作失败，请重试！"), false);
                break;
            default:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作成功！"), false);

                break;
        }
        GridView1.EditIndex = -1;
        BindClass();
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void BindSelectClass()
    {
        classtypeid = Convert.ToInt32(ddlctype.SelectedValue);
        string keyword = txtkeyword.Text.Trim();
        if (!CoreTools.ProcessSqlStr(keyword, 0))
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert(ConfigHelper.ProcessSqlStrErroMsg), false);
        }
        else 
        {
            // 获取GridView排序数据列及排序方向
            string sortExpression = this.GridView2.Attributes["SortExpression"];
            string sortDirection = this.GridView2.Attributes["SortDirection"];

            DataSet ds = jtDataAccess.FilterClass(id, classtypeid, 2, keyword);
            if (CoreTools.CheckDataSet(ds))
            {
                // 根据GridView排序数据列及排序方向设置显示的默认数据视图
                if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
                {
                    ds.Tables[0].DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
                }

                // GridView绑定并显示数据
                //this.GridView2.DataSource = ds.Tables[0];
              //  this.GridView2.DataBind();
                GridviewControl.GridViewDataBind(this.GridView2, ds.Tables[0]);
               // pager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0]["Total"]);
                FinishClass = Convert.ToInt32(hdfFinishClass.Value);
                if (FinishClass == 1)
                {
                    btnDeleteAdd.Enabled = true;
                    ibtnsearch.Enabled = true;
                    selectAll.Enabled = true;
                }
                else
                {
                    btnDeleteAdd.Enabled = false;
                    ibtnsearch.Enabled = false;
                    selectAll.Enabled = false;
                }

            }
            else
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("ClassId");
                dt.Columns.Add("ClassTypeId");
                dt.Columns.Add("Code");
                dt.Columns.Add("ClassTypeName");
                dt.Columns.Add("Name");
                dt.Columns.Add("Time");
                dt.Columns.Add("IsValidDesc");

                dt.Columns.Add("");
                GridviewControl.GridViewDataBind(this.GridView2, dt);

                GridviewControl.ResetGridView(this.GridView2);
                btnDeleteAdd.Enabled = false;
                selectAll.Enabled = false;

            }
        }
        GridviewControl.ResetGridView(this.GridView1);
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //首先判断是否是数据行
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FCFDEE'");
            //当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            e.Row.Cells[1].Attributes.Add("class", "text");
            Label lblstartdate = (Label)e.Row.FindControl("lblstartdate");
            Label lblenddate = (Label)e.Row.FindControl("lblenddate");
            TextBox txtStartDate = (TextBox)e.Row.FindControl("txtStartDate");
            TextBox txtEndDate = (TextBox)e.Row.FindControl("txtEndDate");
            Button btnchange = (Button)e.Row.FindControl("btnchange");
            if (lblstartdate != null && lblstartdate.Text != "")
            {
                lblstartdate.Text = Convert.ToDateTime(lblstartdate.Text).ToShortDateString().Replace("1900/1/1", "");
            }
            if (lblenddate != null && lblenddate.Text != "")
            {
                lblenddate.Text = Convert.ToDateTime(lblenddate.Text).ToShortDateString().Replace("1900/1/1", "").Replace("2099/12/31", "");
            }
            if (txtStartDate != null && txtStartDate.Text != "")
            {
                txtStartDate.Text = Convert.ToDateTime(txtStartDate.Text).ToShortDateString().Replace("1900/1/1", "");
            }
            if (txtEndDate != null && txtEndDate.Text != "")
            {
                txtEndDate.Text = Convert.ToDateTime(txtEndDate.Text).ToShortDateString().Replace("1900/1/1", "").Replace("2099/12/31", "");
            }
            if (e.Row.Cells.Count > 10)
            {
                LinkButton BtnDelete = (LinkButton)e.Row.Cells[8].Controls[2];
                if (BtnDelete != null && BtnDelete.Text == "删除")
                {
                    ((LinkButton)e.Row.Cells[8].Controls[2]).Attributes.Add("onclick", "javascript:return confirm('您确定要删除该记录吗？')");
                }
            }
            if (edit == 1 && btnchange!=null)
            {
                btnchange.Visible = true;
            }
            else if (btnchange != null)
            {
                btnchange.Visible = false;
            }

        }
        if (FinishClass == 1)
        {
            if (edit == 1)
                ((CommandField)GridView1.Columns[8]).ShowEditButton = true;
            else
                ((CommandField)GridView1.Columns[8]).ShowEditButton = false;
            if (delete == 1)
                ((CommandField)GridView1.Columns[8]).ShowDeleteButton = true;
            else
                ((CommandField)GridView1.Columns[8]).ShowDeleteButton = false;
        }
        else
        {
            ((CommandField)GridView1.Columns[8]).ShowEditButton = false;
            ((CommandField)GridView1.Columns[8]).ShowDeleteButton = false;
        }
      
    }
    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        // 从事件参数获取排序数据列
        string sortExpression = e.SortExpression.ToString();

        // 假定为排序方向为“顺序”
        string sortDirection = "ASC";

        // “ASC”与事件参数获取到的排序方向进行比较，进行GridView排序方向参数的修改
        if (sortExpression == this.GridView1.Attributes["SortExpression"])
        {
            //获得下一次的排序状态
            sortDirection = (this.GridView1.Attributes["SortDirection"].ToString() == sortDirection ? "DESC" : "ASC");
        }

        // 重新设定GridView排序数据列及排序方向
        this.GridView1.Attributes["SortExpression"] = sortExpression;
        this.GridView1.Attributes["SortDirection"] = sortDirection;

        this.BindClass();
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        UserType ut = new UserType();//用户自定义类型
        DataTable StudyTable = ut.GetStudyTableType();
        int studyid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
        DataRow StudyTableRow;

        StudyTableRow = StudyTable.NewRow();
        StudyTableRow["StudyId"] = studyid;
        StudyTable.Rows.Add(StudyTableRow);
        StudyTable.AcceptChanges();
        int flag = jtDataAccess.OpStudy(JTDataAccess.OpType.Delete, StudyTable);

        switch (flag)
        {
            case 0:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("删除失败！"), false);
                break;

            case 1:
                ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("删除成功！"), false);
                break;
            default:
                break;
        }

        GridView1.EditIndex = -1;
        BindClass();
        GridviewControl.ResetGridView(this.GridView2);

    }
    protected void btnexport_Click(object sender, EventArgs e)
    {
       // DataTable dt = GetExportData();
      //  ExcelExport(GetStringWriter(dt), "正在学习讲授的课程.xls");
        DataTable dt = GetExportData();
       if (GridView1.Rows.Count == 1 && GridView1.Rows[0].Cells[0].Text ==GridviewControl.EmptyText)
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("没有数据，不需要导出吧！"), false);
        else
        {
            string style = @"<style> .text { mso-number-format:\@;color:#000000 } </style> ";

            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.Charset = "GB2312";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("正在学习讲授的课程.xls", System.Text.Encoding.GetEncoding("utf-8")));
            HttpContext.Current.Response.ContentType = "application/ms-excel";

            StringWriter sw = new StringWriter();

            HtmlTextWriter htw = new HtmlTextWriter(sw);
            GridView1.Columns[0].Visible = false;
            GridView1.Columns[8].Visible = false;
            GridView1.Columns[9].Visible = false;
            GridView1.AllowPaging = false;
            GridView1.AllowSorting = false;
            GridView1.DataSource = dt;
            GridView1.DataBind();
            GridView1.RenderControl(htw);

            // Style is added dynamically
            Response.Write(style);

            Response.Write(sw.ToString());

            Response.End();
        }
        GridviewControl.ResetGridView(this.GridView1);
        GridviewControl.ResetGridView(this.GridView2);
    }
    public override void VerifyRenderingInServerForm(Control control)
    {

    }
    protected DataTable GetExportData()
    {
        DataTable dt = new DataTable();
        // 获取GridView排序数据列及排序方向
        string sortExpression = this.GridView1.Attributes["SortExpression"];
        string sortDirection = this.GridView1.Attributes["SortDirection"];
        DataSet ds = jtDataAccess.GetEmpInfo(id);
        if (ds != null && ds.Tables.Count >2 && ds.Tables[2].Rows.Count > 0)
        {
            // 根据GridView排序数据列及排序方向设置显示的默认数据视图
            if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
            {
                ds.Tables[2].DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
            }

            dt = ds.Tables[2];

        }
        return dt;

    }
    protected void ExcelExport(StringWriter sw, string exportFileName)
    {

        HttpContext.Current.Response.ClearContent();
        HttpContext.Current.Response.Charset = "GB2312";
        HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(exportFileName, System.Text.Encoding.GetEncoding("utf-8")));
        HttpContext.Current.Response.ContentType = "application/ms-excel";
        // HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\" />");
        HttpContext.Current.Response.Write(sw.ToString());
        HttpContext.Current.Response.End();


    }
    //将datatable中的数据进行组装，比如添加列头（这样excel文件中第一行就看到列头名称） 
    public static StringWriter GetStringWriter(DataTable dt)
    {
        StringWriter sw = new StringWriter();

        //先写列的表头，这样保证如果没有数据也能输出列表头 
        sw.Write("课程编号" + "\t ");
        sw.Write("课程类型" + "\t ");
        sw.Write("课程名称" + "\t ");
        sw.Write("课程小时数" + "\t ");
        sw.Write("开始日期" + "\t ");
        sw.Write("结束日期" + "\t ");
        sw.Write(sw.NewLine);

        //如果包含数据 
        if (dt != null)
        {
            //写数据 
            foreach (DataRow dr in dt.Rows)
            {
                sw.Write(dr["Code"].ToString() + "\t ");
                sw.Write(dr["ClassTypeName"].ToString() + "\t ");
                sw.Write(dr["Name"].ToString() + "\t ");
                sw.Write(dr["Time"].ToString() + "\t ");
                sw.Write(DateTime.Parse(dr["StartDate"].ToString()).ToShortDateString().Replace("1900/1/1","") + "\t ");
                sw.Write(DateTime.Parse(dr["EndDate"].ToString()).ToShortDateString().Replace("2099/12/31", "") + "\t ");
                //换行 
                sw.Write(sw.NewLine);
            }
        }
        sw.Close();
        return sw;
    }
    protected void btnDeleteAdd_Click(object sender, EventArgs e)
    {
        UserType ut = new UserType();//用户自定义类型
        DataTable StudyTable = ut.GetStudyTableType();
        int count = 0;
        DataRow StudyTableRow;
        for (int i = 0; i <= GridView2.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView2.Rows[i].FindControl("chkID");
            HiddenField hdfClassId = (HiddenField)GridView2.Rows[i].FindControl("hdfClassId");
            if (cbox.Checked == true && hdfClassId != null && hdfClassId.Value != "")
            {
                count++;
                DateTime? sdate = null;
                DateTime? edate = null;
                if (txtstartdate.Text.Trim()!="")
                    sdate = DateTime.Parse(txtstartdate.Text.Trim());
                if(txtenddate.Text.Trim()!="")
                    edate = DateTime.Parse(txtenddate.Text.Trim());
                StudyTableRow = StudyTable.NewRow();
                StudyTableRow["EmpId"] = id;
                StudyTableRow["ClassId"] = hdfClassId.Value;
                if (sdate == null)
                    StudyTableRow["StartDate"] = DBNull.Value;
                else
                     StudyTableRow["StartDate"] = sdate;
                if (edate == null)
                    StudyTableRow["EndDate"] = DBNull.Value;
                else
                    StudyTableRow["EndDate"] = edate;
                StudyTable.Rows.Add(StudyTableRow);
            }
        }
        if (count == 0)
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("您还未选择任何一项！"), false);
        }
        else
        {
            StudyTable.AcceptChanges();
            int flag = jtDataAccess.OpStudy(JTDataAccess.OpType.Insert, StudyTable);

            switch (flag)
            {
                case 0:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("添加失败！"), false);
                    break;

                case 1:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("添加成功！"), false);
                    BindClass();
                    this.BindSelectClass();
                    break;

                default:
                    break;
            }
            selectAll.Checked = false;
        }
        GridviewControl.ResetGridView(this.GridView1);
    }
    protected void selectAll_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView2.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView2.Rows[i].FindControl("chkID");
            if (selectAll.Checked == true)
            {
                cbox.Checked = true;
            }
            else
            {
                cbox.Checked = false;
            }
        }
        GridviewControl.ResetGridView(this.GridView1);
    }
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        //首先判断是否是数据行
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //当鼠标停留时更改背景色
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FCFDEE'");
            //当鼠标移开时还原背景色
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

        }
    }
    protected void GridView2_Sorting(object sender, GridViewSortEventArgs e)
    {
        // 从事件参数获取排序数据列
        string sortExpression = e.SortExpression.ToString();

        // 假定为排序方向为“顺序”
        string sortDirection = "ASC";

        // “ASC”与事件参数获取到的排序方向进行比较，进行GridView排序方向参数的修改
        if (sortExpression == this.GridView2.Attributes["SortExpression"])
        {
            //获得下一次的排序状态
            sortDirection = (this.GridView2.Attributes["SortDirection"].ToString() == sortDirection ? "DESC" : "ASC");
        }

        // 重新设定GridView排序数据列及排序方向
        this.GridView2.Attributes["SortExpression"] = sortExpression;
        this.GridView2.Attributes["SortDirection"] = sortDirection;

        this.BindSelectClass();
        GridviewControl.ResetGridView(this.GridView1);

    }
    protected void ibtnsearch_Click(object sender, ImageClickEventArgs e)
    {
        BindSelectClass();
    }
    protected void btnDeleteMass_Click(object sender, EventArgs e)
    {
        UserType ut = new UserType();//用户自定义类型
        DataTable StudyTable = ut.GetStudyTableType();
        int count = 0;
        DataRow StudyTableRow;
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("chkID1");
            HiddenField hdfStudyId = (HiddenField)GridView1.Rows[i].FindControl("hdfStudyId");
            if (cbox.Checked == true && hdfStudyId != null && hdfStudyId.Value != "")
            {
                count++;
                StudyTableRow = StudyTable.NewRow();
                StudyTableRow["StudyId"] = hdfStudyId.Value;
                StudyTable.Rows.Add(StudyTableRow);
            }
        }
        if (count == 0)
        {
            ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("您还未选择任何一项！"), false);
        }
        else
        {
            StudyTable.AcceptChanges();
            int flag = jtDataAccess.OpStudy(JTDataAccess.OpType.Delete, StudyTable);

            switch (flag)
            {
                case 0:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("删除失败！"), false);
                    break;

                case 1:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("删除成功！"), false);
                    BindClass();
                    break;

                default:
                    break;
            }
            selectAll1.Checked = false;
        }
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void selectAll1_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("chkID1");
            if (selectAll1.Checked == true)
            {
                cbox.Checked = true;
            }
            else
            {
                cbox.Checked = false;
            }
        }
        GridviewControl.ResetGridView(this.GridView2);
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("change"))
        {
            GridViewRow drv = ((GridViewRow)(((Button)(e.CommandSource)).Parent.Parent)); //此得出的值是表示那行被选中的索引值 

            int flag = 0;
            int studyid = Convert.ToInt32(e.CommandArgument.ToString());
            int classid = Convert.ToInt32(((HiddenField)drv.FindControl("hdfclassId1")).Value);

            UserType ut = new UserType();//用户自定义类型
            DataTable StudyTable = ut.GetStudyTableType();
            DataRow StudyTableRow;
            StudyTableRow = StudyTable.NewRow();
            StudyTableRow["StudyId"] = studyid;
            StudyTableRow["EmpId"] = id;
            StudyTableRow["ClassId"] = classid;
            StudyTableRow["StartDate"] = DBNull.Value;
            StudyTableRow["EndDate"] = DBNull.Value;

            StudyTable.Rows.Add(StudyTableRow);
            flag = jtDataAccess.OpStudy(JTDataAccess.OpType.Change, StudyTable);
            switch (flag)
            {
                case 1:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作成功！"), false);
                    break;
                case 0:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作失败，请重试！"), false);
                    break;
                default:
                    ScriptManager.RegisterStartupScript(up1, this.GetType(), "alert", CoreTools.JsAlert("操作成功！"), false);

                    break;
            }
            GridView1.EditIndex = -1;
            BindClass();
        }
        GridviewControl.ResetGridView(this.GridView2);

    }
}